import mongoengine as db
from app.libs.enums import LimitType


class TypeLimit(db.EmbeddedDocument):
    meta = {
        'abstract': True,
        'strict': False,
    }

    used = db.IntField(default=0)
    total = db.LongField(default=0)
    number = db.IntField(default=0)
    time = db.LongField(default=0)     # limitType == exp  time 存入模块过期时间点
    limitType = db.StringField(default='limit', choices=[item.value for item in LimitType])
    taskType = db.StringField(default='')


class TypeMax(TypeLimit):
    limitType = db.StringField(default='max', choices=[item.value for item in LimitType])


class TypePeriod(TypeLimit):
    limitType = db.StringField(default='period', choices=[item.value for item in LimitType])


class TypeFreq(TypeLimit):
    limitType = db.StringField(default='frequency', choices=[item.value for item in LimitType])


class TypeDuration(TypeLimit):
    limitType = db.StringField(default='duration', choices=[item.value for item in LimitType])


class TypeLimitTotal50(TypeLimit):
    total = db.LongField(min_value=0, default=50)


class TypeLimitTotal20(TypeLimit):
    total = db.LongField(min_value=0, default=20)


class TypeLimitTotal5(TypeLimit):
    total = db.LongField(min_value=0, default=5)


class TypeFreqTotal3(TypeLimit):
    limitType = db.StringField(default=LimitType.frequency.value, choices=[item.value for item in LimitType])
    total = db.LongField(min_value=0, default=3)


class TypeFreqTotal10(TypeLimit):
    limitType = db.StringField(default=LimitType.frequency.value, choices=[item.value for item in LimitType])
    total = db.LongField(min_value=0, default=10)


class TypeFreqTotal100000(TypeLimit):
    limitType = db.StringField(default=LimitType.frequency.value, choices=[item.value for item in LimitType])
    total = db.LongField(min_value=0, default=100000)


class TypeFreqTotal5(TypeLimit):
    limitType = db.StringField(default=LimitType.frequency.value, choices=[item.value for item in LimitType])
    total = db.LongField(min_value=0, default=5)


class TypeFreqTotal1000(TypeLimit):
    limitType = db.StringField(default=LimitType.frequency.value, choices=[item.value for item in LimitType])
    total = db.LongField(min_value=0, default=1000)


class TypeFreqTotal100(TypeLimit):
    limitType = db.StringField(default=LimitType.frequency.value, choices=[item.value for item in LimitType])
    total = db.LongField(min_value=0, default=100)


class TypePeriodTotal5(TypeLimit):
    limitType = db.StringField(default=LimitType.period.value, choices=[item.value for item in LimitType])
    total = db.LongField(min_value=0, default=5)


class ExpTypeLimit(TypeLimit):
    limitType = db.StringField(default=LimitType.exp.value, choices=[item.value for item in LimitType])
